<template>
  <div class="boxg">
    <!-- 头部 -->
    <div class="htear">
      <div class="left">
        <div
          @click="$router.go(-1)"
          class="return iconfont icon-arrowRight-copy-copy"
        ></div>
        <div class="name">{{ name }}</div>
      </div>
      <div class="right">
        <router-link
          tag="div"
          to="/search"
          class="searchcon iconfont icon-31sousuo"
        ></router-link>
        <div
          is-link
          @click="showPopup"
          class="classification iconfont icon-a-gengduofenlei"
        ></div>
      </div>
    </div>
    <!-- 弹出内容 -->
    <van-popup
      closeable
      v-model="show"
      position="top"
      :style="{ height: '45%' }"
    >
      <div class="boxpopup">
        <!-- 头部 -->
        <div class="htears">
          <div class="left">
            <div
              @click="$router.go(-1)"
              class="return iconfont icon-arrowRight-copy-copy"
            ></div>
            <div class="name">{{name}}</div>
          </div>
        </div>
        <!-- 分类 -->
        <div class="guide-nav">
          <router-link tag="div" to="/schoolboy" class="box">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-home-copy"></use>
            </svg>
            <div class="boxtext">首页</div>
          </router-link>
          <router-link tag="div" to="/classification" class="box">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-fenlei"></use>
            </svg>
            <div>分类</div>
          </router-link>
          <router-link tag="div" to="/rankinglist" class="box">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-daochu1024-02"></use>
            </svg>
            <div>排行榜</div>
          </router-link>
          <router-link tag="div" to="/cover" class="box">
            <svg class="icon" aria-hidden="true">
              <use
                xlink:href="#icon-a-travelhotelholidayvacationcdlistingboo"
              ></use>
            </svg>
            <div>免费</div>
          </router-link>
          <router-link tag="div" to="/end" class="box">
            <svg class="icon sw" aria-hidden="true">
              <use xlink:href="#icon-wanjietuijian"></use>
            </svg>
            <div>完本</div>
          </router-link>
          <router-link tag="div" to="/okami" class="box">
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-huangguan"></use>
            </svg>
            <div>大神</div>
          </router-link>
        </div>
        <!-- 我的书架 -->
        <router-link tag="div" to="/bookshelf" class="mybookshelf">我的书架</router-link>
      </div>
    </van-popup>
    <!-- 书籍列表 -->
    <div class="newarrivals">
      <div
        @click="bookdeta(item.id)"
        v-for="(item, index) in rush.slice(0, nums)"
        :key="index"
        class="newbook"
      >
        <div class="left">
          <img :src="item.newbookimages" alt="" />
        </div>
        <div class="right">
          <div class="top">{{ item.bookname }}</div>
          <div class="centenr">
            {{ item.newbookintroduce }}
          </div>
          <div class="bottom">
            <div class="bookname">
              <span class="iconfont icon-31wode"></span>{{ item.author }}
            </div>
            <div class="label">
              <span>{{ item.type }}</span
              ><span>{{ item.serial }}</span
              ><span>{{ item.words }}万字</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <footers></footers>
  </div>
</template>

<script>
import footers from "../components/base/footers.vue";
export default {
  components: { footers },
  data() {
    return {
      show: false, //弹出判断
      // 书籍列表数据
      rush: [],
      //遍历的数据多少
      nums: 10,
      name: null,
    };
  },
  created() {
    let name = this.$route.query;
    console.log(name.name);
    this.name = name.name;
    this.$axios.get("/static.json").then((res) => {
      let data = res.data;
      if (this.name == "新书抢鲜") {
        this.rush = data.rush; //新书抢鲜列表
      } else {
        this.rush = data.endbook; //畅销完本列表
      }
    });
  },
  mounted() {
    window.addEventListener("scroll", this.getScroll);
  },
  //   destroyed() {
  //     window.removeEventListener("scroll", this.getScroll);
  //   },
  methods: {
    //监听滚动
    getScroll() {
      // console.log("滚动高度", window.pageYOffset);
      //   console.log(
      //     "距离顶部高度",
      //     this.$refs.obtain.getBoundingClientRect().top
      //   );

      // 获取页面高度
      // console.log(document.documentElement.clientHeight);
      let ffoheight = document.documentElement.clientHeight;
      // 获取滚动条上距离顶部高度
      //   let scrollheight = window.pageYOffset;
      //   console.log(scrollheight)
      // 获取页面总长度
      let scrollHeight = document.body.scrollHeight;
      // 获取滚动条上距离顶部高度(兼容)
      let scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop;

      //   console.log(document.body.scrollHeight);

      //   console.log(scrollheight);

      //通过页面高度来决定加载的多少
      if (ffoheight + scrollTop >= scrollHeight) {
        setTimeout(() => {
          this.nums += 5;
        }, 300);
      }
    },
    //头部弹出
    showPopup() {
      this.show = true;
    },
    // 路由跳转传参
    bookdeta(id) {
      this.$router.push({
        path: "/bookdetails",
        query: {
          id: id
        },
      });
    },
  },
};
</script>

<style lang="less">
.boxg {
  background-color: white;
  .boxpopup {
    .htears {
      width: 100%;
      display: flex;
      height: 22px;
      padding: 11px 0px 10px 0px;
      justify-content: space-between;
      align-items: center;
      .left,
      .right {
        display: flex;
        div {
          padding: 0px 10px;
          text-align: center;
          font-size: 18px;
          color: #3c3b3b;
        }
        .name {
          font-size: 14px;
          color: #424141;
        }
        .return {
          color: black;
        }
      }
    }
    .guide-nav {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      padding: 0px 16px;
      .box {
        width: 58px;
        height: 58px;
        line-height: 58px;
        text-align: center;
        margin: 12px 24px;
        div {
          position: relative;
          top: -33px;
          font-size: 14px;
        }
      }
    }
    .mybookshelf {
      margin: 20px 50px;
      text-align: center;
      padding: 8px 0px;
      font-size: 14px;
      color: white;
      font-weight: 500;
      background-color: #ed424b;
      border-radius: 20px;
    }
    .sw {
      font-size: 40px;
    }
  }
  .htear {
    width: 100%;
    display: flex;
    height: 22px;
    padding: 11px 0px 10px 0px;
    justify-content: space-between;
    align-items: center;
    background-color: #ffffff;
    border-bottom: 1px solid #efefef;
    margin-bottom: 12px;
    .left,
    .right {
      display: flex;
      div {
        padding: 0px 10px;
        text-align: center;
        font-size: 18px;
        color: #3c3b3b;
      }
      .name {
        font-size: 14px;
        color: #424141;
      }
      .return {
        color: black;
      }
    }
  }
  .newarrivals {
    display: flex;
    flex-direction: column;
    padding: 0px 15px;
    background-color: white;
    .newbook {
      padding-bottom: 10px;
      margin-bottom: 10px;
      width: 100%;
      display: flex;
      border-bottom: 1px solid #ebedf1;
      .left {
        width: 66px;
        height: 88px;
        margin-right: 8px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .right {
        width: 269px;
        .top {
          font-size: 16px;
          font-weight: 900;
          color: #33373d;
          line-height: 1.4;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .centenr {
          color: #969ba3;
          font-size: 14px;
          line-height: 1.1875rem;
          display: -webkit-box;
          height: 2.25rem;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
          margin: 6px 0;
        }
        .bottom {
          display: flex;
          color: #969ba3;
          font-size: 12px;
          justify-content: space-between;
          .bookname {
            font-size: 13px;
            .icon-31wode {
              margin-right: 3px;
              font-size: 13px;
            }
          }
          .label {
            display: flex;
            span {
              margin-left: 2px;
              font-size: 12px;
              display: block;
              padding: 1px 2px;
              transform: scale(0.8);
            }
            span:nth-child(1) {
              border: 1px solid #969ba3;
              color: #969ba3;
            }
            span:nth-child(2) {
              border: 1px solid #ed424b;
              color: #ed424b;
            }
            span:nth-child(3) {
              border: 1px solid #008dff;
              color: #008dff;
            }
          }
        }
      }
    }
    .newbook:nth-child(3) {
      border-block: 0px;
    }
  }
}
</style>